package com.hou.edustatistics.schedule;

import com.hou.edustatistics.service.StatisticsDailyService;
import com.hou.edustatistics.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author shkstart
 * @create 2021-12-16-18:11
 */
@Component
public class ScheduleTask {

    @Autowired
    private StatisticsDailyService service;

//    // 每隔5秒执行该方法
//    springboot只支持6为cron第7为年不能设置
//    @Scheduled(cron = "0/5 * * * * ?")
//    public void taskTest(){
//        System.out.println("........执行了task方法");
//    }

    // 每天24：00自动生成数据前一天数据
    @Scheduled(cron = "0 0 0 * * ?")
    public void createData(){
        String date = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        service.registerCount(date);
    }


}
